package com.ye.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ye.entity.User;
import com.ye.service.UserService;
import com.ye.mapper.UserMapper;
import com.ye.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.function.BiPredicate;

/**
 * @author EDY
 * @description 针对表【user】的数据库操作Service实现
 * @createDate 2022-03-18 14:20:34
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserByUserName(User user) {
        return userMapper.selectOne(new QueryWrapper<User>().eq("username", user.getUsername()));
    }

    @Override
    public Integer editPassword(User user) {
        String password = user.getPassword();
        User md5User = Md5Util.md5Password(user);
        return userMapper.update(null, new UpdateWrapper<User>().eq("username", user.getUsername()).set("password",md5User.getPassword()).set("salt",md5User.getSalt()));
    }

    @Override
    public Integer editUserInfo(User user) {
        return userMapper.update(null, new UpdateWrapper<User>().eq("username", user.getUsername()).set("email",user.getEmail()).set("logo",user.getLogo()));
    }

    @Override
    public Integer editStatus(User user) {
        return userMapper.update(null, new UpdateWrapper<User>().eq("username", user.getUsername()).set("state", user.getState()));
    }

    @Override
    public Integer updateSignature(User user) {
        return userMapper.update(null,new UpdateWrapper<User>().eq("username", user.getUsername()).set("signature",user.getSignature()));
    }


}




